import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/course/csMealsOrder/list',
  edit = '/course/csMealsOrder/edit',
  save='/course/csMealsOrder/batchAdd',
  batchUnsubscribe='/course/csMealsOrder/batchUnsubscribe',
  deleteOne = '/course/csMealsOrder/delete',
  deleteBatch = '/course/csMealsOrder/deleteBatch',
  importExcel = '/course/csMealsOrder/importExcel',
  exportXls = '/course/csMealsOrder/exportXls',
  approveRefund='/course/csMealsOrder/approveRefund'
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 批量添加就餐单
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url =Api.save;
  return defHttp.post({url: url, params});
}
/**
 * 
 * @param params 批量退订
 * @param isUpdate 
 * @returns 
 */
export const batchUnsubscribe = (params, isUpdate) => {
  let url =Api.batchUnsubscribe;
  return defHttp.post({url: url, params});
}


/**
 * 审批就餐单 退订
 * @param params
 */
export const approveRefund = (params,handleSuccess) => {
    return defHttp.post({url: Api.approveRefund, params}).then(() => {
      handleSuccess();
    });
}

/**
 * 单人退订
 * @param params
 */
export const oneRefund = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认退订',
    content: '是否操作选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.post({url: Api.edit, params}).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 单人撤销
 * @param params
 */
export const oneEvoke = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认撤销',
    content: '是否操作选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.post({url: Api.edit, params}).then(() => {
        handleSuccess();
      });
    }
  });
}